﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using PrjBaseWithAuth4.Domain.Entities;

namespace PrjBaseWithAuth4.Domain.Concrete
{
    public class EFDbContext : DbContext
    {
        //
        // 用户表
        //public virtual DbSet<B_User> B_Users { get; set; }
        //ublic System.Data.Entity.DbSet<Reminders.Domain.ViewModels.VM_Task_List> VM_Task_List { get; set; }

        public virtual DbSet<S_Portal> s_portals { get; set; }

        public EFDbContext()
            : base("DefaultConnection")
        {
            //引用DefaultConnection
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // 将 FOREIGN KEY 约束 'FK_dbo.S_Users_dbo.S_Portals_s_portal_id' 引入表 'S_Users' 可能会导致循环或多重级联路径。
            // 请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION，或修改其他 FOREIGN KEY 约束。
            /*
            modelBuilder.Entity<S_User>()
                .HasRequired(e => e.s_portal)
                .WithMany(e => e.s_Users)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<S_Department>()
                .HasRequired(e => e.s_portal)
                .WithMany(e => e.s_Departments)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<S_Tab>()
                .HasRequired(e => e.s_portal);
             */

            /*
            modelBuilder.Entity<S_Code_Sort>()
                .Property(x => x.sort_code). .IsMaxLength().HasMaxLength(30);
             */

            /*
            modelBuilder.Entity<B_Task>()
                .HasMany(e => e.B_Reviews)
                .WithRequired(e => e.B_Tasks)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<B_Task>()
                .HasMany(e => e.B_TaskViews)
                .WithRequired(e => e.B_Tasks)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<B_Task>()
                .HasMany(e => e.B_Unit_Tasks)
                .WithRequired(e => e.B_Tasks)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<B_Unit>()
                .HasMany(e => e.B_Unit_Tasks)
                .WithRequired(e => e.B_Units)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<B_User>()
                .HasMany(e => e.B_Reviews)
                .WithRequired(e => e.B_Users)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<B_User>()
                .HasMany(e => e.B_TaskViews)
                .WithRequired(e => e.B_Users)
                .WillCascadeOnDelete(false);
             */
        }
    }
}
